/*
 * @Description: 异步插件
 * @Author: wangqi
 * @Date: 2021-04-24 22:06:30
 * @LastEditTime: 2021-04-24 22:16:11
 */

/*
    plugins顺序正常按照数组下标顺序执行
    emit钩子在done钩子之前执行
*/

class AsyncPlugin {
    apply(compiler) {
        console.log(2);
        compiler.hooks.emit.tapAsync('AsyncPlugin', (compliation, cb) => {
            setTimeout(() => {
                console.log("文件发射出来， 等一下");
                cb();
            }, 1000)
        });

        compiler.hooks.emit.tapPromise('AsyncPlugin', (compliation) => {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log("在等一秒");
                    resolve();
                }, 1000)
            })

        });
    }
}

module.exports = AsyncPlugin;